package com.xyhy.core.base.model.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.xyhy.core.base.entity.IObject;
import io.swagger.annotations.ApiModel;
import jakarta.persistence.Transient;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;

import java.util.Objects;

@Getter
@Setter
@SuperBuilder
@NoArgsConstructor
@ApiModel(value = "对象DTO的基类")
public class ObjectDTO<ID> implements IObject<ID> {
  private ID id;
  private String name;

  @Transient
  @JsonIgnore
  private boolean isNew;

  public ObjectDTO(ID id, String name) {
    this.id = id;
    this.name = name;
  }

  @Override
  public boolean equals(Object o) {
    if (this == o)
      return true;
    if (o == null || getClass() != o.getClass())
      return false;
    ObjectDTO<?> objectDTO = (ObjectDTO<?>) o;
    return id.equals(objectDTO.id);
  }

  @Override
  public int hashCode() {
    return Objects.hash(id);
  }

  @Transient
  @JsonIgnore
  @Override
  public boolean isNew() {
    return isNew;
  }
}
